{% extends 'blog_base.html' %}

{% block main %}
    {% for post in post_list %}
        <article class="post post-{{ post.pk }}">
            <header class="entry-header">
                <h1 class="entry-title">
                    <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
                </h1>
                <div class="entry-meta">
                    <span class="post-category"><a
                            href="{% url 'blog:category' post.category.pk %}">{{ post.category.name }}</a></span>
                    <span class="post-date"><a href=""><time class="entry-date"
                                                             datetime="2012-11-09T23:15:57+00:00">{{ post.create_time }}</time></a></span>
                    <span class="post-author"><a href="">{{ post.author }}</a></span>
                    <span class="comments-link"><a href="">{{ post.comment_set.count }} 评论</a></span>
                    <span class="views-count"><a href="">{{ post.views }} 阅读</a></span>
                </div>
            </header>
            <div class="entry-content clearfix">
                <p>{{ post.excerpt }}...</p>
                <div class="read-more cl-effect-14">
                    <a href="{{ post.get_absolute_url }}" class="more-link">继续阅读<span class="meta-nav">→</span></a>
                </div>
            </div>
        </article>
    {% empty %}
        <div class="no-post">暂时还没发布文章！</div>
    {% endfor %}

    {#  根据 Paginator 生成分页  #}
    {#    {% if is_paginated %}#}
    {#        <div class="pagination-simple">#}
    {#            {% if page_obj.has_previous %}#}
    {#                <a href="?page={{ page_obj.previous_page_number }}">上一页</a>#}
    {#            {% endif %}#}
    {##}
    {#            <span class="current">第 {{ page_obj.number }} 页 / 共 {{ paginator.num_pages }} 页</span>#}
    {##}
    {#            {% if page_obj.has_next %}#}
    {#                <a href="?page={{ page_obj.next_page_number }}">下一页</a>#}
    {#            {% endif %}#}
    {#        </div>#}
    {#    {% endif %}#}

    {#  自定义分页  #}
    {% if is_paginated %}
        <div class="pagination">
            {% if first %}
                <a href="?page=1">1</a>
            {% endif %}

            {% if left %}
                {% if left_has_more %}
                    <span>...</span>
                {% endif %}

                {% for page in left %}
                    <a href="?page={{ page }}" style="color: black">{{ page }}</a>
                {% endfor %}
            {% endif %}

            <a href="?page={{ page_obj.number }}" style="color: red">{{ page_obj.number }}</a>

            {% if right %}
                {% for page in right %}
                    <a href="?page={{ page }}">{{ page }}</a>
                {% endfor %}

                {% if right_has_more %}
                    <span>...</span>
                {% endif %}
            {% endif %}

            {% if last %}
                <a href="?page={{ paginator.num_pages }}">{{ paginator.num_pages }}</a>
            {% endif %}
        </div>
    {% endif %}
{% endblock main %}

{% block toc %}
    <div class="widget widget-content">
        <h3 class="widget-title">文章目录</h3>
        {{ post.toc|safe }}
    </div>
{% endblock %}


